﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="AddNewMember.aspx.cs" Inherits="masterPages_customer_AddNewMember" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script type="text/javascript">
    var existExtNameList;
    function CusExtWin(visible, id) {
        if (document.layers) {
            theObj = eval("document.layers[\'" + id + "\']");
            if (theObj) {
                theObj.visibility = visible;
            }
        }
        else if (document.all) {
            if (visible == 'show') visible = 'visible';
            if (visible == 'hide') visible = 'hidden';
            theObj = eval("document.all[\'" + id + "\']");
            if (theObj) {
                theObj.style.visibility = visible;
            }
        }
        document.getElementById("extN").value = "";
        document.getElementById("extV").value = "";
    }
    function OnClearBtnClick() {
        CusExtWin('hide', 'boysoft');
    }
    function OnAddNewCusExtClick() {
        var extName = document.getElementById("extN").value;
        var extValue = document.getElementById("extV").value;
        if (!extName || extName == "") {
            alert("扩展字段名不能为空");
            return;
        }
        if (!extValue || extValue == "") {
            alert("扩展字段值不能为空");
            return;
        }
        if (existExtNameList == undefined) {
            existExtNameList = ParseExistNames();
        }
        if (IsExistSameName(extName)) {
            document.getElementById("extN").value = "";
            alert("扩展字段名称重复");
            return;
        }
        alert("1");
        var tbody = document.getElementById("extDetail");
        var tr = document.createElement("tr");
        var td1 = document.createElement("td");
        td1.setAttribute("align", "center");
        td1.appendChild(document.createTextNode(extName));
        tr.appendChild(td1);
        var td2 = document.createElement("td");
        var input = document.createElement("input");
        input.setAttribute("type", "text");
        input.setAttribute("value", extValue);
        td2.appendChild(input);
        tr.appendChild(td2);
        tbody.appendChild(tr);
        alert("2");
        GenerateHiddenExtValue(extName, extValue);
        alert("3");
        existExtNameList.splice(0, 0, extName);
        alert("4");
        CusExtWin('hide', 'boysoft');
        alert("5");
    }
    function IsExistSameName(name) {
        if (existExtNameList) {
            for (var i = 0; i < existExtNameList.length; i++) {
                if (existExtNameList[i].toLowerCase() == name.toLowerCase()) {
                    return true;
                }
            }
        }
        return false;
    }
    function GenerateHiddenExtValue(val1, val2) {
        var splitStr = "#%@%#";
        var hiddenExt = document.getElementById("cusExtHidden");
        var values = hiddenExt.value;
        if (values) {
            values = values + splitStr + HTMLEncode(val1) + splitStr + HTMLEncode(val2);
        } else {
            values = HTMLEncode(val1) + splitStr + HTMLEncode(val2);
        }
        hiddenExt.value = values;
    }
    function HTMLEncode(input) {
        var converter = document.createElement("DIV");
        converter.innerText = input;
        var output = converter.innerHTML;
        converter = null;
        output = output.replace(/<br>/ig, "");
        return output;
    }
    function HTMLDecode(input) {
        var converter = document.createElement("DIV");
        converter.innerHTML = input;
        var output = converter.innerText;
        converter = null;
        return output;
    }
    function ParseExistNames() {
        var names = document.getElementById("existNames").value;
        alert(names);
        names = HTMLDecode(names);
        var arr = names.split("#%@%#");
        return arr;
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <input clientidmode="Static" id="cusExtHidden" type="hidden" runat="server" />
    <input clientidmode="Static" id="existNames" type="hidden" runat="server" />
    <asp:ObjectDataSource ID="SourceCustomerLevel" runat="server" 
        DataObjectTypeName="CustomerLevelDetail" 
        DeleteMethod="DeleteEmployees" OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetEmployees" TypeName="CustomerLevelDB" 
        UpdateMethod="UpdateEmployees"></asp:ObjectDataSource>
    <table width="730" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="34" style="background-image:../../images/bj2.gif"><strong>&nbsp;&nbsp;&nbsp;&nbsp;会员添加</strong></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>
            <table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <table width="577" border="1" align="center" cellpadding="5" style="background-color:#999999">
                            <tr>
                                <td align="center">用户名：</td>
                                <td><asp:TextBox ID="CustomerNameTextBox" runat="server" />
                                    <asp:RequiredFieldValidator ID="NameRequiredFieldValidator" runat="server" 
                                        ControlToValidate="CustomerNameTextBox" ErrorMessage="RequiredFieldValidator" 
                                        ForeColor="Red">用户名不能为空</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">邮箱：</td>
                                <td><asp:TextBox ID="EmailTextBox" runat="server" /></td>
                            </tr>
                            <tr>
                                <td align="center">等级：</td>
                                <td>
                                    <asp:DropDownList ID="LevelDropDownList" runat="server" 
                                        DataSourceID="SourceCustomerLevel" DataTextField="LevelName" 
                                        DataValueField="LevelId" />
                                </td>
                            </tr>
                               <tr>
                                <td align="center">性别：</td>
                                <td>
                                    <asp:DropDownList ID="GenderDropDownList" runat="server">
                                        <asp:ListItem Selected="True">男</asp:ListItem>
                                        <asp:ListItem>女</asp:ListItem>
                                    </asp:DropDownList>
                                   </td>
                            </tr>
                            <tr>
                                <td align="center">电话：</td>
                                <td><asp:TextBox ID="PhoneTextBox" runat="server" /></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td align="center">
                        <input id="Button1" onclick="CusExtWin('show','boysoft')" type="button" value="添加扩展信息" />
                        <table width="577" border="0" align="center" cellpadding="5" style="background-color:#999999">
                            <tbody clientidmode="Static" id="extDetail" runat="server"></tbody>
                        </table>
                    </td>
                </tr>   
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td align="center">
                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/an11.gif" onclick="AddImageButton_Click" />
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/an3.gif" OnClientClick="OnClearBtnClick();" />
                    </td>
                </tr>
            </table>
        </td>
      </tr>
    </table>
    <div id="boysoft" style="HEIGHT: 80px; LEFT: 309px; POSITION: absolute; TOP: 150px; VISIBILITY: hidden; WIDTH: 300px; Z-INDEX: 1"> 
      <table bgcolor="#666666" border="1" width="100%" style="height: 80px">
        <tbody> 
            <tr>
                <td height="65" width="100%"> 
                    <table width="99%" style="height: 80px">
                        <tbody> 
                          <tr> 
                            <td>扩展字段名：</td>
                            <td>扩展字段值：</td>
                          </tr>
                          <tr> 
                            <td><input id="extN" type="text" /></td>
                            <td><input id="extV" type="text" /></td>
                          </tr>
                          <tr align="center"> 
                            <td height="23" width="100%">
                               <input id="AddExtButton" onclick="OnAddNewCusExtClick()" type="button" value="添加" />
                            </td>
                            <td height="23" width="100%">
                               <input id="CancleExtButton" onclick="CusExtWin('hide','boysoft')" type="button" value="取消" />
                            </td>
                          </tr>
                        </tbody> 
                    </table>
                </td>
            </tr>
        </tbody> 
      </table>
    </div>
</asp:Content>

